<?php

if (!defined('IN_XLP')) {
    exit('Access Denied!');
}

/**
 * Description of mapAction
 *
 * @author xlp
 */
class mapAction extends commonAction {

    function __construct() {
        parent::__construct();
        parent::_checkLogin();
        $this->key = '1aa6a77c877c9d026f2f7640bb722f41';
    }

    function index() {
        
    }

    function address() {
        $x = $this->_get('x');
        $y = $this->_get('y');
        if (!$x || !$y) {
            $this->JsonReturn('参数不正确');
        }
        $rs = json_decode(getHttp('http://apis.map.qq.com/ws/geocoder/v1/?location=' . $y . ',' . $x . '&key=' . $this->key), true);
        if (isset($rs['status']) && $rs['status'] == 0) {
//            z($rs['result']);
            if (isHave($rs['result']['address_component']['street_number'])) {
                $path = $rs['result']['address_component']['city'] . $rs['result']['address_component']['district'] . $rs['result']['address_component']['street_number'];
            } else {
                $path = $rs['result']['address_component']['city'] . $rs['result']['address_component']['district'] . $rs['result']['address_component']['street'];
            }
            return $this->JsonReturn('ok', array('location' => $rs['result']['location'], 'address' => $rs['result']['address'], 'component' => $rs['result']['address_component'], 'path' => $path), 1);
        } else {
            return $this->JsonReturn('error');
        }
    }

}
